load("@fbcode_macros//build_defs/lib:rust_oss.bzl", "rust_oss")
load("@fbsource//tools/build_defs:rust_binary.bzl", "rust_binary")
load("@fbsource//tools/target_determinator/macros:ci.bzl", "ci")
load("//eden/mononoke/facebook:lib.bzl", "tokio_dependency_test")

oncall("scm_server_infra")

rust_binary(
    name = "mononoke",
    srcs = glob(["server/src/**/*.rs"]),
    autocargo = {"cargo_toml_dir": "server"},
    labels = [
        ci.heavyweight(),
    ],
    named_deps = {"slog": "//common/rust/shed/tracing_slog_compat:tracing_slog_compat"},
    deps = ([
        "fbsource//third-party/rust:anyhow",
        "fbsource//third-party/rust:async-trait",
        "fbsource//third-party/rust:clap",
        "fbsource//third-party/rust:futures",
        "fbsource//third-party/rust:openssl",
        "fbsource//third-party/rust:tracing",
        "//common/rust/shed/cloned:cloned",
        "//common/rust/shed/fbinit:fbinit",
        "//common/rust/shed/secure_utils:secure_utils",
        "//eden/mononoke/cache_warmup:cache_warmup",
        "//eden/mononoke/cmdlib:cmdlib_logging",
        "//eden/mononoke/cmdlib:environment",
        "//eden/mononoke/cmdlib/mononoke_app:mononoke_app",
        "//eden/mononoke/cmdlib/sharding:executor_lib",
        "//eden/mononoke/cmdlib/sharding_ext:sharding_ext",
        "//eden/mononoke/common/scuba_ext:scuba_ext",
        "//eden/mononoke/metaconfig:metaconfig_types",
        "//eden/mononoke/mononoke_api:mononoke_api",
        "//eden/mononoke/server/repo_listener:repo_listener",
        "//eden/mononoke/repo_attributes/repo_identity:repo_identity",
        "//eden/scm/lib/clientinfo:clientinfo",
    ] + ([] if rust_oss.is_oss_build() else [
        "//eden/mononoke/pushrebase:pushrebase_client",
    ])) + ["fbsource//third-party/rust:tokio"],
)

tokio_dependency_test(
    name = "tokio_check",
    rule = ":mononoke",
)

rust_binary(
    name = "bonsai_verify",
    srcs = glob(["cmds/bonsai_verify/**/*.rs"]),
    named_deps = {"slog": "//common/rust/shed/tracing_slog_compat:tracing_slog_compat"},
    unittests = False,
    deps = [
        "fbsource//third-party/rust:anyhow",
        "fbsource//third-party/rust:clap",
        "fbsource//third-party/rust:futures",
        "fbsource//third-party/rust:serde",
        "fbsource//third-party/rust:serde_derive",
        "fbsource//third-party/rust:tokio",
        "fbsource//third-party/rust:toml",
        "fbsource//third-party/rust:tracing",
        "//common/rust/shed/cloned:cloned",
        "//common/rust/shed/facet:facet",
        "//common/rust/shed/fbinit:fbinit",
        "//common/rust/shed/lock_ext:lock_ext",
        "//eden/mononoke/blobrepo:blobrepo_override",
        "//eden/mononoke/blobrepo_utils:blobrepo_utils",
        "//eden/mononoke/blobstore:blobstore",
        "//eden/mononoke/bonsai_hg_mapping:bonsai_hg_mapping",
        "//eden/mononoke/cmdlib/mononoke_app:mononoke_app",
        "//eden/mononoke/derived_data/mercurial_derivation:mercurial_derivation",
        "//eden/mononoke/mercurial:mercurial_types",
        "//eden/mononoke/mononoke_types:mononoke_types",
        "//eden/mononoke/repo_attributes/commit_graph/commit_graph:commit_graph",
        "//eden/mononoke/repo_attributes/repo_blobstore:repo_blobstore",
        "//eden/mononoke/repo_attributes/repo_derived_data:repo_derived_data",
        "//eden/mononoke/repo_attributes/restricted_paths:restricted_paths",
        "//eden/mononoke/server/context:context",
    ],
)

rust_binary(
    name = "blobimport",
    srcs = ["cmds/blobimport.rs"],
    autocargo = {"cargo_toml_dir": "blobimport"},
    named_deps = {"slog": "//common/rust/shed/tracing_slog_compat:tracing_slog_compat"},
    test_deps = [
        "//common/rust/shed/fbinit:fbinit-tokio",
        "//eden/mononoke/mononoke_macros:mononoke_macros",
    ],
    deps = [
        "fbsource//third-party/rust:anyhow",
        "fbsource//third-party/rust:ascii",
        "fbsource//third-party/rust:clap",
        "fbsource//third-party/rust:futures",
        "fbsource//third-party/rust:tracing",
        "//common/rust/shed/fbinit:fbinit",
        "//eden/mononoke/blobimport_lib:blobimport_lib",
        "//eden/mononoke/bonsai_globalrev_mapping:bonsai_globalrev_mapping",
        "//eden/mononoke/cmdlib/mononoke_app:mononoke_app",
        "//eden/mononoke/commit_rewriting/synced_commit_mapping:synced_commit_mapping",
        "//eden/mononoke/common/sql_construct:sql_construct",
        "//eden/mononoke/mercurial:mercurial_revlog",
        "//eden/mononoke/mercurial:mercurial_types",
        "//eden/mononoke/mononoke_types:mononoke_types",
        "//eden/mononoke/mutable_counters:mutable_counters",
        "//eden/mononoke/repo_attributes/commit_graph/commit_graph:commit_graph",
        "//eden/mononoke/repo_attributes/repo_identity:repo_identity",
        "//eden/mononoke/server/context:context",
        "//manifold/clients/rust:manifold_client",
    ],
)

rust_binary(
    name = "blobstore_healer",
    srcs = glob(["cmds/blobstore_healer/**/*.rs"]),
    autocargo = {"cargo_toml_dir": "blobstore_healer"},
    named_deps = {
        "futures_03_ext": "//common/rust/shed/futures_ext:futures_ext",
        "slog": "//common/rust/shed/tracing_slog_compat:tracing_slog_compat",
    },
    test_deps = [
        "fbsource//third-party/rust:bytes",
        "//common/rust/shed/fbinit:fbinit-tokio",
        "//eden/mononoke/mononoke_macros:mononoke_macros",
    ],
    deps = [
        "fbsource//third-party/rust:anyhow",
        "fbsource//third-party/rust:async-trait",
        "fbsource//third-party/rust:chrono",
        "fbsource//third-party/rust:clap",
        "fbsource//third-party/rust:futures",
        "fbsource//third-party/rust:itertools",
        "fbsource//third-party/rust:rand",
        "fbsource//third-party/rust:tokio",
        "fbsource//third-party/rust:tracing",
        "//common/rust/shed/borrowed:borrowed",
        "//common/rust/shed/cached_config:cached_config",
        "//common/rust/shed/cloned:cloned",
        "//common/rust/shed/fbinit:fbinit",
        "//eden/mononoke/blobstore:blobstore",
        "//eden/mononoke/blobstore:blobstore_factory",
        "//eden/mononoke/blobstore_sync_queue:blobstore_sync_queue",
        "//eden/mononoke/cmdlib/mononoke_app:mononoke_app",
        "//eden/mononoke/common/rust/sql_ext:sql_ext",
        "//eden/mononoke/common/sql_construct:sql_construct",
        "//eden/mononoke/common/wait_for_replication:wait_for_replication",
        "//eden/mononoke/metaconfig:metaconfig_types",
        "//eden/mononoke/mononoke_types:mononoke_types",
        "//eden/mononoke/server/context:context",
    ],
)

rust_binary(
    name = "aliasverify",
    srcs = ["cmds/aliasverify.rs"],
    autocargo = {"cargo_toml_dir": "aliasverify"},
    named_deps = {"slog": "//common/rust/shed/tracing_slog_compat:tracing_slog_compat"},
    deps = [
        "fbsource//third-party/rust:anyhow",
        "fbsource//third-party/rust:async-trait",
        "fbsource//third-party/rust:bytes",
        "fbsource//third-party/rust:clap",
        "fbsource//third-party/rust:futures",
        "fbsource//third-party/rust:tokio",
        "fbsource//third-party/rust:tracing",
        "//common/rust/shed/facet:facet",
        "//common/rust/shed/fbinit:fbinit",
        "//eden/mononoke/blobstore:blobstore",
        "//eden/mononoke/cmdlib/mononoke_app:mononoke_app",
        "//eden/mononoke/cmdlib/sharding:executor_lib",
        "//eden/mononoke/cmdlib/sharding_ext:sharding_ext",
        "//eden/mononoke/filestore:filestore",
        "//eden/mononoke/mercurial:mercurial_types",
        "//eden/mononoke/metaconfig:metaconfig_types",
        "//eden/mononoke/mononoke_repos:mononoke_repos",
        "//eden/mononoke/mononoke_types:mononoke_types",
        "//eden/mononoke/mutable_counters:mutable_counters",
        "//eden/mononoke/repo_attributes/commit_graph/sql_commit_graph_storage:sql_commit_graph_storage",
        "//eden/mononoke/repo_attributes/repo_blobstore:repo_blobstore",
        "//eden/mononoke/repo_attributes/repo_identity:repo_identity",
        "//eden/mononoke/server/context:context",
    ],
)

rust_binary(
    name = "backfill_mapping",
    srcs = ["cmds/backfill_mapping.rs"],
    deps = [
        "fbsource//third-party/rust:anyhow",
        "fbsource//third-party/rust:ascii",
        "fbsource//third-party/rust:clap",
        "fbsource//third-party/rust:futures",
        "fbsource//third-party/rust:futures-util",
        "//common/rust/shed/cloned:cloned",
        "//common/rust/shed/facet:facet",
        "//common/rust/shed/fbinit:fbinit",
        "//eden/mononoke/blobstore:blobstore",
        "//eden/mononoke/bonsai_git_mapping:bonsai_git_mapping",
        "//eden/mononoke/bonsai_hg_mapping:bonsai_hg_mapping",
        "//eden/mononoke/bonsai_svnrev_mapping:bonsai_svnrev_mapping",
        "//eden/mononoke/cmdlib/mononoke_app:mononoke_app",
        "//eden/mononoke/mercurial:mercurial_types",
        "//eden/mononoke/repo_attributes/repo_blobstore:repo_blobstore",
        "//eden/mononoke/server/context:context",
    ],
)

rust_binary(
    name = "statistics_collector",
    srcs = ["cmds/statistics_collector.rs"],
    autocargo = {"cargo_toml_dir": "statistics_collector"},
    named_deps = {
        "futures_ext": "//common/rust/shed/futures_01_ext:futures_01_ext",
        "slog": "//common/rust/shed/tracing_slog_compat:tracing_slog_compat",
    },
    test_deps = [
        "fbsource//third-party/rust:bytes",
        "fbsource//third-party/rust:maplit",
        "fbsource//third-party/rust:tokio",
        "//common/rust/shed/borrowed:borrowed",
        "//eden/mononoke/bonsai_hg_mapping:bonsai_hg_mapping",
        "//eden/mononoke/mononoke_macros:mononoke_macros",
        "//eden/mononoke/tests/fixtures:fixtures",
        "//eden/mononoke/tests/utils:tests_utils",
    ],
    deps = [
        "fbsource//third-party/rust:anyhow",
        "fbsource//third-party/rust:async-trait",
        "fbsource//third-party/rust:clap",
        "fbsource//third-party/rust:futures",
        "fbsource//third-party/rust:serde_json",
        "fbsource//third-party/rust:tokio",
        "fbsource//third-party/rust:tracing",
        "//common/rust/shed/facet:facet",
        "//common/rust/shed/fbinit:fbinit",
        "//common/rust/shed/stats:stats",
        "//eden/mononoke/blobrepo:blobrepo_hg",
        "//eden/mononoke/blobstore:blobstore",
        "//eden/mononoke/blobstore:redactedblobstore",
        "//eden/mononoke/bonsai_hg_mapping:bonsai_hg_mapping",
        "//eden/mononoke/bookmarks:bookmarks",
        "//eden/mononoke/cmdlib/mononoke_app:mononoke_app",
        "//eden/mononoke/cmdlib/sharding:executor_lib",
        "//eden/mononoke/cmdlib/sharding_ext:sharding_ext",
        "//eden/mononoke/common/scuba_ext:scuba_ext",
        "//eden/mononoke/derived_data/mercurial_derivation:mercurial_derivation",
        "//eden/mononoke/filestore:filestore",
        "//eden/mononoke/manifest:manifest",
        "//eden/mononoke/mercurial:mercurial_types",
        "//eden/mononoke/mononoke_types:mononoke_types",
        "//eden/mononoke/repo_attributes/commit_graph/commit_graph:commit_graph",
        "//eden/mononoke/repo_attributes/repo_blobstore:repo_blobstore",
        "//eden/mononoke/repo_attributes/repo_derived_data:repo_derived_data",
        "//eden/mononoke/repo_attributes/repo_identity:repo_identity",
        "//eden/mononoke/server/context:context",
    ],
)

rust_binary(
    name = "sqlblob_gc",
    srcs = glob(["cmds/sqlblob_gc/**/*.rs"]),
    named_deps = {"slog": "//common/rust/shed/tracing_slog_compat:tracing_slog_compat"},
    test_deps = [],
    deps = [
        "fbsource//third-party/rust:anyhow",
        "fbsource//third-party/rust:bytesize",
        "fbsource//third-party/rust:clap",
        "fbsource//third-party/rust:futures",
        "fbsource//third-party/rust:tracing",
        "//common/rust/shed/fbinit:fbinit",
        "//common/rust/shed/futures_retry:futures_retry",
        "//eden/mononoke/blobstore:blobstore_factory",
        "//eden/mononoke/blobstore:sqlblob",
        "//eden/mononoke/cmdlib:cmdlib_logging",
        "//eden/mononoke/cmdlib/mononoke_app:mononoke_app",
        "//eden/mononoke/metaconfig:metaconfig_types",
        "//eden/mononoke/mononoke_macros:mononoke_macros",
        "//eden/mononoke/server/context:context",
    ],
)

rust_binary(
    name = "packer",
    srcs = glob(["cmds/packer/**/*.rs"]),
    named_deps = {"slog": "//common/rust/shed/tracing_slog_compat:tracing_slog_compat"},
    test_deps = [
        "//eden/mononoke/mononoke_macros:mononoke_macros",
    ],
    deps = [
        "fbsource//third-party/rust:anyhow",
        "fbsource//third-party/rust:clap",
        "fbsource//third-party/rust:futures",
        "fbsource//third-party/rust:rand",
        "fbsource//third-party/rust:regex",
        "fbsource//third-party/rust:tokio",
        "fbsource//third-party/rust:tracing",
        "//common/rust/shed/borrowed:borrowed",
        "//common/rust/shed/fbinit:fbinit",
        "//common/rust/shed/futures_retry:futures_retry",
        "//eden/mononoke/blobstore:blobstore",
        "//eden/mononoke/blobstore:blobstore_factory",
        "//eden/mononoke/blobstore:packblob",
        "//eden/mononoke/cmdlib/mononoke_app:mononoke_app",
        "//eden/mononoke/common/scuba_ext:scuba_ext",
        "//eden/mononoke/metaconfig:metaconfig_types",
        "//eden/mononoke/server/context:context",
    ],
)

rust_binary(
    name = "check_git_wc",
    srcs = glob(["cmds/check_git_wc/**/*.rs"]),
    test_deps = [],
    deps = [
        "fbsource//third-party/rust:anyhow",
        "fbsource//third-party/rust:clap",
        "fbsource//third-party/rust:git2",
        "//common/rust/shed/facet:facet",
        "//common/rust/shed/fbinit:fbinit",
        "//eden/mononoke/cmdlib/mononoke_app:mononoke_app",
        "//eden/mononoke/git/check_git_wc:check_git_wc",
        "//eden/mononoke/mononoke_types:mononoke_types",
        "//eden/mononoke/repo_attributes/repo_blobstore:repo_blobstore",
        "//eden/mononoke/repo_attributes/repo_derived_data:repo_derived_data",
        "//eden/mononoke/repo_attributes/repo_identity:repo_identity",
        "//eden/mononoke/server/context:context",
    ],
)
